﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using RFIDSystem.Controllers;
using RFIDSystem.IServices;
using RFIDSystem.Model;
using RFIDSystem.Model.Models;
using RFIDSystem.Model.ViewModels;

namespace RFIDSystem.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize(Permissions.Name)]
    public class RFIDController : BaseApiController
    {
        public IRfidServices _rfidServices;

        public RFIDController(IRfidServices rfidServices)
        {
            _rfidServices = rfidServices;
        }

        [HttpGet]
        public async Task<MessageModel<List<RFIDViewModel>>> GetRfids()
        {
            var rs = await _rfidServices.GetRFIDs();
            return new MessageModel<List<RFIDViewModel>>()
            {
                msg = "获取成功！",
                response = rs
            };
        }
        [HttpPost]
        public async Task<MessageModel<bool>> AddRFID([FromBody] RFID input)
        {
            var rs = await _rfidServices.AddRFID(input);
            return new MessageModel<bool>()
            {
                msg = "获取成功！",
                response = rs
            };
        }
        
        [HttpDelete]
        public async Task<MessageModel<bool>> DelRFID(string id)
        {
            var rs = await _rfidServices.DelRFID(id);
            return new MessageModel<bool>()
            {
                msg = "获取成功！",
                response = rs
            };
        }
    }
}